/**
 * Copyright (c) 2010-2020 by skzr.org
 * All rights reserved.
 * @Author <a href="mailto:skzr.org@gmail.com">skzr.org</a>
 * @date 2011-3-14 下午09:15:23
 */
package org.skzr.logging;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import org.skzr.logging.impl.MessageConveyor;
import org.skzr.logging.impl.SLF4JLocationAwareLog;
import org.skzr.logging.impl.SLF4JLogger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.spi.LocationAwareLogger;

/**
 * 本地日志器工厂
 * @author <a href="mailto:skzr.org@gmail.com">skzr.org</a>
 * @version 1.0.0
 * @since JDK1.6
 */
public final class LocalLoggerFactory { // NOPMD by skzrorg on 11-3-14 下午10:00
	private static Map<String, ILocalLogger> loggerMap = new HashMap<String, ILocalLogger>();
	
	private LocalLoggerFactory() {
	}
	
	public static ILocalLogger getLogger(Class<?> clazz) {
		return getLogger(clazz.getName());
	}
	
	public static ILocalLogger getLogger(String name) {
		ILocalLogger instance = loggerMap.get(name);
		if (instance != null) return instance;
		
		synchronized (loggerMap) {
			 Logger logger = LoggerFactory.getLogger(name);
			 MessageConveyor msgConveyor = new MessageConveyor(Locale.getDefault());
			 instance = logger instanceof LocationAwareLogger ? new SLF4JLocationAwareLog((LocationAwareLogger) logger, msgConveyor)
			 	: new SLF4JLogger(logger, msgConveyor);
			 loggerMap.put(name, instance);
		}
		return instance;
	}
	
}
